package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类管理模块")
public class ClassificationControllerr {
    @Autowired
    private ClassificationService classificationService;

    @ApiOperation(value = "分页查询分类")
    @GetMapping("/page")
    public Result selectAllCategory(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = classificationService.selectAllCategory(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation(value = "新增分类")
    @PostMapping
    public Result insertCategory(@RequestBody Category category){
        classificationService.insertCategory(category);
        return Result.success();
    }

    @ApiOperation(value = "删除分类")
    @DeleteMapping
    public Result deleteCategory(Long id){
        classificationService.deleteCategory(id);
        return Result.success();
    }

    @ApiOperation(value = "修改分类")
    @PutMapping
    public Result updateCateegory(@RequestBody CategoryDTO categoryDTO){
        classificationService.updaateCategory(categoryDTO);
        return Result.success();
    }

    @ApiOperation(value = "启用禁用的分类")
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        classificationService.updateCategory(status,id);
        return Result.success();
    }

    @ApiOperation("根据类型分类管理")
    @GetMapping("/list")
    public Result selectCategoryByType(Integer type){
        List<Category> category = classificationService.selectCategoryByType(type);
        return Result.success(category);
    }

}